﻿using Microsoft.Win32;
using Sobiens.SPCamlStudio.Common;
using Sobiens.SPCamlStudio.Common.Threading;
using Sobiens.SPCamlStudio.Entities.Interfaces;
using Sobiens.SPCamlStudio.Entities.Settings;
using Sobiens.SPCamlStudio.Entities.SharePoint;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Sobiens.SPCamlStudio.UI
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window, ISPCamlStudio
    {
        public IQueriesPanel QueriesPanel { get { return this.queriesPanel; } }
        public IQueryDesignerToolbar QueryDesignerToolbar { get { return this.queryDesignerToolbar; } }
        public IServerObjectExplorer ServerObjectExplorer { get { return this.serverObjectExplorer; } }

        public MainWindow()
        {
            InitializeComponent();
        }

        private void serverObjectExplorer_After_Select(object parentFolder, object folder)
        {
            ApplicationContext.Current.SPCamlStudio.QueryDesignerToolbar.ValidateButtonEnabilities();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            ApplicationContext.SetApplicationManager(new Sobiens.SPCamlStudio.UI.SPCamlStudioApplicationManager(this));
            ApplicationContext.Current.Initialize();
        }

        private void Window_Initialized(object sender, EventArgs e)
        {
        }

        private void SaveMenuItem_Click(object sender, RoutedEventArgs e)
        {
            ApplicationContext.Current.Save();
        }

        private void ExitMenuItem_Click(object sender, RoutedEventArgs e)
        {
            Application.Current.Shutdown();
        }

        private void OpenMenuItem_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            if (openFileDialog.ShowDialog() == true)
                ApplicationContext.Current.Load(openFileDialog.FileName);
        }

        private void HelpMenuItem_Click(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Process.Start("https://spcamlstudio.codeplex.com");
        }
    }
}
